<template>
  <div class="wrapper">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <div class="icon" v-for="item in iconList" :key="item.id">
          <img :src="item.imgUrl"/>
          <p>{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {// 计算属性
    pages () {
      const pages = []
      // 对每一项数据进行循环
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-wrapper{
    height:0;
    padding-bottom :50%;
  }
  .wrapper >>> .swiper-container-horizontal > .swiper-pagination-bullets{
    bottom :-2px;
  }
  .wrapper{
    .icon{
      width:25%;
      height:0;
      padding-bottom :25%;
      overflow :hidden;
      text-align:center;
      float:left;
      img{
        width: 65%;
        margin-top :.1rem;
      }
    }
  }
</style>
